import redis
from django.shortcuts import  HttpResponse
from phones import models
import json
from phones.models import Comparation

r = redis.Redis(host="49.234.96.95", port=6379, db=0, password="Gem1234@")

def goodsInfo(request):  #对应原型图手机详情页面
    all=[]
    goods_id = request.GET.get("id")
    goods = models.PhoneInfo.objects.get(id=goods_id)
    goods_brand = goods.p_brand
    goods_brands = models.PhoneInfo.objects.filter(p_brand=goods_brand)
    goods_detail = models.DetailParam.objects.filter(d_number=goods.p_number)[0]
    infoList = []
    count = 0
    for i in goods_brands:
        if count == 5:
            break
        objs = {    #推荐同品牌商品 只查5个
            "id": i.id,
            "title": i.p_title,
            "brand": i.p_brand,
            "img": i.p_img,
            "price": i.p_price,
            "number": i.p_number,
            "href": i.p_href,
            "updateTime": str(i.p_updateTime),
            "store": i.p_store,
            "comment_num": i.p_comment_num,
            "plate":i.p_plate,
               }
        infoList.append(objs)
        count += 1
    all.append(infoList)

    goods_info = goods
    obj = {        #这个商品的详细参数
        "id": goods_info.id,
        "title": goods_info.p_title,
        "brand": goods_info.p_brand,
        "img": goods_info.p_img,
        "price": goods_info.p_price,
        "href": goods_info.p_href,
        "updateTime": str(goods_info.p_updateTime),
        "store": goods_info.p_store,
        "comment_num": goods_info.p_comment_num,
        "plate": goods_info.p_plate,

        "details_id": goods_detail.id,
        "number": goods_detail.d_number,
        "weight": goods_detail.d_weight,
        "cpuType": goods_detail.d_cpuType,
        "ram": goods_detail.d_ram,
        "rom": goods_detail.d_rom,
        "bcamera": goods_detail.d_bcamera, #back后摄像
        "fcamera": goods_detail.d_fcamera, #front前摄像
        "mainScreen": goods_detail.d_mainScreen,
        "resolution": goods_detail.d_resolution,
        "d_os": goods_detail.d_os,
    }
    all.append(obj)
    jsondata = json.dumps(all)

    return HttpResponse(jsondata)

def detailPara(request):          #填充网页对比框
    l=[]
    details = models.Comparation.objects.all()
    for i in details:
        phones = models.PhoneInfo.objects.get(id=i.phone_id)
        details = models.DetailParam.objects.get(id=i.phone_id)
        obj = {
            "infos_id": phones.id,
            "title": phones.p_title,
            "brand": phones.p_brand,
            "price": phones.p_price,
            "href": phones.p_href,
            "updateTime": str(phones.p_updateTime),
            "number": phones.p_number,
            "img": phones.p_img,
            "comment_num": phones.p_comment_num,
            "store": phones.p_store,

            "details_id": details.id,
            "weight": details.d_weight,
            "cpuType": details.d_cpuType,
            "ram": details.d_ram,
            "rom": details.d_rom,
            "bcamera": details.d_bcamera, #back后摄像
            "fcamera": details.d_fcamera, #front前摄像
            "mainScreen": details.d_mainScreen,
            "resolution": details.d_resolution,
            "os": details.d_os,
             }
        l.append(obj)
    jsondata = json.dumps(l)
    return HttpResponse(jsondata)

def compare(request):   #添加到对比列表
    goods_id = request.GET.get("id")
    user_id = request.GET.get("user_id")
    if user_id == 'undefined':
        return HttpResponse("请先登录")
    now_goods_ids = models.Comparation.objects.all()
    for i in now_goods_ids:
        if i.phone_id == goods_id:
            return HttpResponse("不能对比重复商品")
    goods = models.PhoneInfo.objects.get(id=goods_id)
    detailInfo = models.DetailParam.objects.filter(d_number=goods.p_number)[0]
    models.Comparation.objects.create(co_cpuType=detailInfo.d_cpuType,co_plate=goods.p_plate,co_os=detailInfo.d_os,co_comment_num=goods.p_comment_num,co_store=goods.p_store,co_title=goods.p_title, co_price=int(float(goods.p_price)*100),co_img=goods.
                                      p_img,phone_id=goods_id,user_id=user_id,co_bcamera=detailInfo.d_bcamera,
                                      co_fcamera=detailInfo.d_fcamera,co_mainScreen=detailInfo.d_mainScreen,co_ram=detailInfo.d_ram,
                                      co_rom=detailInfo.d_rom,co_weight=detailInfo.d_weight,co_resolution=detailInfo.d_resolution,
                                    )
    return HttpResponse(1)

def clearComparation(request):      #清空对比列表
    try:
        Comparation.objects.filter(id__gt=0).delete()
    except Exception as e:
        print(e)
    return HttpResponse(1)

def deleteOne(request):            #删除对比列表指定物品
    uid = request.GET.get("uid")
    goods_id = request.GET.get("id")  #要一个手机的id(PhoneInfo表下的)
    try:
        models.Comparation.objects.get(phone_id=goods_id, user_id=uid).delete()
    except Exception as e:
        print(e)
        return HttpResponse(0)
    return HttpResponse(1)

allPageNum = []         #手动缓存总页数
def pageNum(request):
    l = []
    brand = request.GET.get("brand")            #品牌id
    pn = request.GET.get("pn")
    startnum = (int(pn)-1)*12
    endnumber = int(pn)*12
    # allnum = ''
    # if allPageNum == []:
    brand = models.BrandCategory.objects.get(id=brand).b_name
    allphones = models.PhoneInfo.objects.filter(p_brand=brand)
    allnum = int(len(allphones)/12)
    if len(allphones) % 12 != 0:
        allnum = allnum + 1
    # allPageNum.append(allnum)
    # else:
    #     allnum = allPageNum[-1]
    if int(pn) <= 0 or int(pn) > int(allnum):
        return HttpResponse(0)
    # [startnum: endnumber]
    phones = allphones[startnum: endnumber]
    for i in phones:
        obj = {
            "id": i.id,
            "title": i.p_title,
            "price": i.p_price,
            "number": i.p_number,
            "img": i.p_img,
            "brand": i.p_brand,
            "comment_num": i.p_comment_num,
            "store": i.p_store,
            "href": i.p_href,
        }
        l.append(obj)
    l.append({
        "allnum":allnum
    })
    jsondata = json.dumps(l)
    # allPageNum.clear()
    return HttpResponse(jsondata)

def orderByCommentNum(request):  #按评论数量排序
    byNumList = []
    com_nums = models.PhoneInfo.objects.all().order_by('p_comment_num')
    for i in com_nums:
        obj = {
            "id": i.id,
            "title": i.p_title,
            "price": i.p_price,
            "href": i.p_href,
            "number": i.p_number,
            "img": i.p_img,
            "store": i.p_store,
            "brand": i.p_brand,
            "comment_num": i.p_comment_num,
            "plate": i.p_plate,
               }
        byNumList.append(obj)
    jsondata = json.dumps(byNumList)
    return HttpResponse(jsondata)

def orderByPrice(request):    #按价格排序
    byPriceList = []
    com_nums = models.PhoneInfo.objects.all().order_by('p_price')
    for i in com_nums:
        obj = {
            "id": i.id,
            "title": i.p_title,
            "price": i.p_price,
            "href": i.p_href,
            "number": i.p_number,
            "img": i.p_img,
            "store": i.p_store,
            "brand": i.p_brand,
            "comment_num": i.p_comment_num,
            "plate": i.p_plate,
               }
        byPriceList.append(obj)
    jsondata = json.dumps(byPriceList)
    return HttpResponse(jsondata)

def selectByScreen(request):  #屏幕尺寸筛选
    l = []
    phonelist = []
    arg = request.GET.get("screen")
    obj = models.DetailParam.objects.all()
    if len(arg) == 8:
        a = str(arg).split("英寸")
        size = int(int(a[0].replace(".", "")) / 10)
        if a[1][2] == "上":
            for i in obj:
                if i.d_mainScreen.split("英寸")[0] != "其它" and i.d_mainScreen.split("英寸")[0] != "其他" and len(i.d_mainScreen.split("英寸")[0]) <= 10:
                    tabledata = float(i.d_mainScreen.split("英寸")[0])
                    if tabledata >= size:
                        phonelist.append(i.d_number)
            o = models.PhoneInfo.objects.filter(p_number__in=phonelist)
            for i in o:
                obj1 = {
                    "id": i.id,
                    "title": i.p_title,
                    "brand": i.p_brand,
                    "img": i.p_img,
                    "price": i.p_price,
                    "number": i.p_number,
                    "href": i.p_href,
                    "store": i.p_store,
                    "comment_num": i.p_comment_num,
                    "plate": i.p_plate,
                }
                l.append(obj1)

        if a[1][2] == "下":
            for i in obj:
                if i.d_mainScreen.split("英寸")[0] != "其它" and i.d_mainScreen.split("英寸")[0] != "其他" and len(i.d_mainScreen.split("英寸")[0]) <= 10:
                    tabledata = float(i.d_mainScreen.split("英寸")[0])
                    if tabledata <= size:
                        phonelist.append(i.d_number)
            o = models.PhoneInfo.objects.filter(p_number__in=phonelist)
            for i in o:
                obj1 = {
                    "id": i.id,
                    "title": i.p_title,
                    "brand": i.p_brand,
                    "img": i.p_img,
                    "price": i.p_price,
                    "number": i.p_number,
                    "href": i.p_href,
                    "store": i.p_store,
                    "comment_num": i.p_comment_num,
                    "plate": i.p_plate,
                }
                l.append(obj1)

    if len(arg) == 11:
        b = str(arg).split("英寸")
        size1 = int(b[0].replace(".", ""))/10
        size2 = int(b[1][1:].replace(".",""))/10
        for i in obj:
            if i.d_mainScreen.split("英寸")[0] != "其它" and len(i.d_mainScreen.split("英寸")[0]) <= 10:
                tabledata = float(i.d_mainScreen.split("英寸")[0])
                if tabledata >= size1 and tabledata <= size2:
                    phonelist.append(i.d_number)
        o = models.PhoneInfo.objects.filter(p_number__in=phonelist)
        for i in o:
            obj1 = {
                "id": i.id,
                "title": i.p_title,
                "brand": i.p_brand,
                "img": i.p_img,
                "price": i.p_price,
                "number": i.p_number,
                "href": i.p_href,
                "store": i.p_store,
                "comment_num": i.p_comment_num,
                "plate": i.p_plate,
            }
            l.append(obj1)

    if len(arg) == 5:
        c = str(arg).split("英寸")
        size = int(c[0].replace(".", ""))/10
        for i in obj:
            if i.d_mainScreen.split("英寸")[0] != "其它" and len(i.d_mainScreen.split("英寸")[0]) <= 10:
                tabledata = float(i.d_mainScreen.split("英寸")[0])
                if tabledata == size:
                    phonelist.append(i.d_number)
        o = models.PhoneInfo.objects.filter(p_number__in=phonelist)
        for i in o:
            obj1 = {
                "id": i.id,
                "title": i.p_title,
                "brand": i.p_brand,
                "img": i.p_img,
                "price": i.p_price,
                "number": i.p_number,
                "href": i.p_href,
                "store": i.p_store,
                "comment_num": i.p_comment_num,
                "plate": i.p_plate,
            }
            l.append(obj1)

    if str(arg) == "其他":
        for i in obj:
            if i.d_mainScreen.split("英寸")[0] == "其它" and len(i.d_mainScreen.split("英寸")[0]) <= 10:
                phonelist.append(i.d_number)
        o = models.PhoneInfo.objects.filter(p_number__in=phonelist)
        for i in o:
            obj1 = {
                "id": i.id,
                "title": i.p_title,
                "brand": i.p_brand,
                "img": i.p_img,
                "price": i.p_price,
                "number": i.p_number,
                "href": i.p_href,
                "store": i.p_store,
                "comment_num": i.p_comment_num,
                "plate": i.p_plate,
            }
            l.append(obj1)

    jsondata = json.dumps(l)
    return HttpResponse(jsondata)

def selectByROM(request):  #筛选手机储存空间
    l = []
    phonelist = []
    arg = request.GET.get("ROM")
    alldata = models.DetailParam.objects.all()
    a = str(arg).split("GB")[0]

    if str(arg) == "其他":
        for i in alldata:
            rom_num = i.d_rom.split("GB")[0]
            if rom_num == "其它存储":
                phonelist.append(i.d_number)
        o = models.PhoneInfo.objects.filter(p_number__in=phonelist)
        for i in o:
            obj1 = {
                "id": i.id,
                "title": i.p_title,
                "brand": i.p_brand,
                "img": i.p_img,
                "price": i.p_price,
                "number": i.p_number,
                "href": i.p_href,
                "store": i.p_store,
                "comment_num": i.p_comment_num,
                "plate": i.p_plate,
            }
            l.append(obj1)

    else:
        if str(arg).split("GB")[1] == '':
            for i in alldata:
                rom_num = i.d_rom.split("GB")[0]
                if rom_num != "其它存储":
                    if int(rom_num) == int(a):
                        phonelist.append(i.d_number)
            o = models.PhoneInfo.objects.filter(p_number__in=phonelist)
            for i in o:
                obj1 = {
                    "id": i.id,
                    "title": i.p_title,
                    "brand": i.p_brand,
                    "img": i.p_img,
                    "price": i.p_price,
                    "number": i.p_number,
                    "href": i.p_href,
                    "store": i.p_store,
                    "comment_num": i.p_comment_num,
                    "plate": i.p_plate,
                }
                l.append(obj1)

        if str(arg).split("GB")[1] == '及以下':
            for i in alldata:
                rom_num = i.d_rom.split("GB")[0]
                if rom_num != "其它存储":
                    if int(rom_num) <= int(a):
                        phonelist.append(i.d_number)
            o = models.PhoneInfo.objects.filter(p_number__in=phonelist)
            for i in o:
                obj1 = {
                    "id": i.id,
                    "title": i.p_title,
                    "brand": i.p_brand,
                    "img": i.p_img,
                    "price": i.p_price,
                    "number": i.p_number,
                    "href": i.p_href,
                    "store": i.p_store,
                    "comment_num": i.p_comment_num,
                    "plate": i.p_plate,
                }
                l.append(obj1)

    # if str(arg).split("GB")[1] == '及以上':
    #     for i in alldata:
    #         rom_num = i.d_rom.split("GB")[0]
    #         if rom_num != "其它存储":
    #             if int(rom_num) >= int(a):
    #                 o = models.PhoneInfo.objects.filter(p_number=i.d_number)[0]
    #                 obj1 = {
    #                     "id": o.id,
    #                     "title": o.p_title,
    #                     "brand": o.p_brand,
    #                     "img": o.p_img,
    #                     "price": o.p_price,
    #                     "number": o.p_number,
    #                     "href": o.p_href,
    #                     "updateTime": str(o.p_updateTime),
    #                     "store": o.p_store,
    #                     "comment_num": o.p_comment_num,
    #                 }
    #                 l.append(obj1)

    jsondata = json.dumps(l)
    return HttpResponse(jsondata)

def selectByRAM(request):  #筛选手机内存空间
    arg = request.GET.get("RAM")
    l = []
    phonelist = []
    alldata = models.DetailParam.objects.all()
    a = str(arg).split("GB")[0]

    if str(arg) == '其他':
        for i in alldata:
            ram_num = i.d_ram.split("GB")[0]
            if ram_num == "其它内存":
                phonelist.append(i.d_number)
        o = models.PhoneInfo.objects.filter(p_number__in=phonelist)
        for i in o:
            obj1 = {
                "id": i.id,
                "title": i.p_title,
                "brand": i.p_brand,
                "img": i.p_img,
                "price": i.p_price,
                "number": i.p_number,
                "href": i.p_href,
                "store": i.p_store,
                "comment_num": i.p_comment_num,
                "plate": i.p_plate,
            }
            l.append(obj1)
    else:
        if str(arg).split("GB")[1] == '':
            for i in alldata:
                ram_num = i.d_ram.split("GB")[0]
                if ram_num != "其它内存":
                    if int(ram_num) == int(a):
                        phonelist.append(i.d_number)
            o = models.PhoneInfo.objects.filter(p_number__in=phonelist)
            for i in o:
                obj1 = {
                    "id": i.id,
                    "title": i.p_title,
                    "brand": i.p_brand,
                    "img": i.p_img,
                    "price": i.p_price,
                    "number": i.p_number,
                    "href": i.p_href,
                    "store": i.p_store,
                    "comment_num": i.p_comment_num,
                    "plate": i.p_plate,
                }
                l.append(obj1)

        if str(arg).split("GB")[1] == '及以下':
            for i in alldata:
                ram_num = i.d_ram.split("GB")[0]
                if ram_num != "其它内存":
                    if int(ram_num) <= int(a):
                        phonelist.append(i.d_number)
            o = models.PhoneInfo.objects.filter(p_number__in=phonelist)
            for i in o:
                obj1 = {
                    "id": i.id,
                    "title": i.p_title,
                    "brand": i.p_brand,
                    "img": i.p_img,
                    "price": i.p_price,
                    "number": i.p_number,
                    "href": i.p_href,
                    "store": i.p_store,
                    "comment_num": i.p_comment_num,
                    "plate": i.p_plate,
                }
                l.append(obj1)

        if str(arg).split("GB")[1] == '及以上':
            for i in alldata:
                ram_num = i.d_ram.split("GB")[0]
                if ram_num != "其它内存":
                    if int(ram_num) >= int(a):
                        phonelist.append(i.d_number)
            o = models.PhoneInfo.objects.filter(p_number__in=phonelist)
            for i in o:
                obj1 = {
                    "id": i.id,
                    "title": i.p_title,
                    "brand": i.p_brand,
                    "img": i.p_img,
                    "price": i.p_price,
                    "number": i.p_number,
                    "href": i.p_href,
                    "store": i.p_store,
                    "comment_num": i.p_comment_num,
                    "plate": i.p_plate,
                }
                l.append(obj1)

    jsondata = json.dumps(l)
    return HttpResponse(jsondata)

def findByWords(request):  #搜索功能
    l = []
    ids = []
    pn = request.GET.get("pn")
    startnum = (int(pn)-1)*12
    endnumber = int(pn)*12
    words = request.GET.get("words")
    result = r.smembers(words)

    for i in result:
        ids.append(i.decode("utf-8"))

    all = models.PhoneInfo.objects.filter(id__in = ids)
    allnum = int(len(all)/12)
    if len(all) % 12 != 0:
        allnum = allnum + 1
    if int(pn) <= 0 or int(pn) > int(allnum):
        return HttpResponse(0)

    objs = models.PhoneInfo.objects.filter(id__in=ids)[startnum:endnumber]
    for i in objs:
        obj = {
            "id": i.id,
            "title": i.p_title,
            "brand": i.p_brand,
            "price": i.p_price,
            "href": i.p_href,
            "updateTime": str(i.p_updateTime),
            "number": i.p_number,
            "img": i.p_img,
            "comment_num": i.p_comment_num,
            "store": i.p_store,
            "plate": i.p_plate,
        }
        l.append(obj)
    l.append({"allnum": allnum})
    jsondata = json.dumps(l)

    return HttpResponse(jsondata)

def showThreea(request):   #三个苹果
    l=[]
    Apple = models.PhoneInfo.objects.filter(p_brand="Apple")[0:3]
    for i in Apple:
        obj = {
            "a_id": i.id,
            "a_title": i.p_title,
            "a_price": i.p_price,
            "a_img": i.p_img,
            "a_store": i.p_store,
        }
        l.append(obj)
    jsondata = json.dumps(l)
    return HttpResponse(jsondata)

def showThreehw(request):   #三个华为
    l=[]
    huawei = models.PhoneInfo.objects.filter(p_brand="华为")[0:3]
    for i in huawei:
        obj = {
            "hw_id": i.id,
            "hw_title": i.p_title,
            "hw_price": i.p_price,
            "hw_img": i.p_img,
            "hw_store": i.p_store,
        }
        l.append(obj)
    jsondata = json.dumps(l)
    return HttpResponse(jsondata)

def showThreev(request):   #三个vivo
    l=[]
    vivo = models.PhoneInfo.objects.filter(p_brand="vivo")[0:3]
    for i in vivo:
        obj = {
            "v_id": i.id,
            "v_title": i.p_title,
            "v_price": i.p_price,
            "v_img": i.p_img,
            "v_store": i.p_store,
        }
        l.append(obj)
    jsondata = json.dumps(l)
    return HttpResponse(jsondata)

def showFive(request):
    l = []
    phones = models.PhoneInfo.objects.all()[0:5]
    for i in phones:
        obj = {
            "a_id": i.id,
            "a_title": i.p_title,
            "a_price": i.p_price,
            "a_img": i.p_img,
            "a_store": i.p_store,
        }
        l.append(obj)
    jsondata = json.dumps(l)
    return HttpResponse(jsondata)

def showSix(request):
    l = []
    phones = models.PhoneInfo.objects.all()[5:11]
    for i in phones:
        obj = {
            "a_id": i.id,
            "a_title": i.p_title,
            "a_price": i.p_price,
            "a_img": i.p_img,
            "a_store": i.p_store,
        }
        l.append(obj)
    jsondata = json.dumps(l)
    return HttpResponse(jsondata)

def showFour(request):
    l = []
    id1 = request.GET.get("id1")
    id2 = request.GET.get("id2")
    id3 = request.GET.get("id3")
    id4 = request.GET.get("id4")
    ids = [id1,id2,id3,id4]
    for i in ids:
        try:
            if i != None:
                info = models.PhoneInfo.objects.filter(id=i)[0]
                print(info.p_number)
                detail = models.DetailParam.objects.filter(d_number=info.p_number)[0]
                obj = {
                    "id": info.id,
                    "title": info.p_title,
                    "brand": info.p_brand,
                    "img": info.p_img,
                    "price": info.p_price,
                    "href": info.p_href,
                    "updateTime": str(info.p_updateTime),
                    "store": info.p_store,
                    "comment_num": info.p_comment_num,
                    "plate": info.p_plate,

                    "details_id": detail.id,
                    "number": detail.d_number,
                    "weight": detail.d_weight,
                    "cpuType": detail.d_cpuType,
                    "ram": detail.d_ram,
                    "rom": detail.d_rom,
                    "bcamera": detail.d_bcamera, #back后摄像
                    "fcamera": detail.d_fcamera, #front前摄像
                    "mainScreen": detail.d_mainScreen,
                    "resolution": detail.d_resolution,
                    "d_os": detail.d_os,
                }
                l.append(obj)
        except Exception as e:
            print(e)
    jd = json.dumps(l)
    return HttpResponse(jd)

def vegetablePrice(request):
    l = []
    veg = models.PhoneInfo.objects.all().order_by("p_price")[160:200]
    for i in veg:
        if i.p_price != "-1.00":
            obj = {
                "id": i.id,
                "title": i.p_title,
                "price": i.p_price,
                "img": i.p_img,
                "href": i.p_href,
                "brand": i.p_brand,
                "store": i.p_store,
                "plate": i.p_plate,
            }
            l.append(obj)
    print(len(l))
    jd = json.dumps(l)
    return HttpResponse(jd)

def commend(request):
    l = []
    goods = models.PhoneInfo.objects.all().order_by("-p_comment_num")[0:30]
    for i in goods:
        obj = {
            "id": i.id,
            "title": i.p_title,
            "price": i.p_price,
            "img": i.p_img,
            "href": i.p_href,
            "brand": i.p_brand,
            "store": i.p_store,
            "plate": i.p_plate,
            }
        l.append(obj)
    jd = json.dumps(l)
    return HttpResponse(jd)

def findByType(request):
    l = []
    phone_type = request.GET.get("type")
    phones = models.PhoneInfo.objects.filter(p_title__contains=phone_type)
    for i in phones:
        obj = {
            "id": i.id,
            "title": i.p_title,
            "brand": i.p_brand,
            "price": i.p_price,
            "href": i.p_href,
            "updateTime": str(i.p_updateTime),
            "number": i.p_number,
            "img": i.p_img,
            "comment_num": i.p_comment_num,
            "store": i.p_store,
            "plate": i.p_plate,
        }
        l.append(obj)
    jd = json.dumps(l)
    return HttpResponse(jd)


def showCompare(request):
    l = []
    uid = request.GET.get("uid")
    goods = models.Comparation.objects.filter(user_id=uid)
    for i in goods:
        obj = {
            "id": i.id,
            "title": i.co_title,
            "price": i.co_price,
            "img": i.co_img,
            "ram": i.co_ram,
            "rom": i.co_rom,
            "resolution": i.co_resolution,
            "mainScreen": i.co_mainScreen,
            "bcamera": i.co_bcamera,
            "fcamera": i.co_fcamera,
            "weight": i.co_weight,

            "plate": i.co_plate,
            "os": i.co_os,
            "comment_num": i.co_comment_num,
            "store": i.co_store,
            "cpuType": i.co_cpuType,
        }
        l.append(obj)
    jd = json.dumps(l)
    return HttpResponse(jd)



